<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>帖子分页列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .post-card {
            margin-bottom: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
    </style>
</head>
<body>
<div class="container mt-5">
    <h2>帖子列表</h2>

    <!-- 帖子卡片 -->
    <div th:each="item : ${pageResult.records}">
        <div class="post-card">
            <h5>
                <a th:href="@{/user/index/detail/{contextId}(contextId=${item.id})}" th:text="${item.title}"></a>
            </h5>
            <p th:text="${item.context}"></p>
            <small class="text-muted">作者：[[${item.userId}]] | 发布时间：[[${#temporals.format(item.createTime, 'yyyy-MM-dd HH:mm')}]] | 评论数：[[${item.commentCount}]]</small>
        </div>
    </div>

    <!-- 分页导航 -->
    <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center">
            <li class="page-item" th:classappend="${pageResult.pageNum == 1} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/user/index/1}" th:if="${pageResult.pageNum > 1}">首页</a>
                <a class="page-link" th:href="@{/user/index/1}" th:unless="${pageResult.pageNum > 1}">首页</a>
            </li>
            <li class="page-item" th:classappend="${pageResult.pageNum == 1} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/user/index/{page}(page=${pageResult.pageNum - 1})}" th:if="${pageResult.pageNum > 1}">上一页</a>
                <a class="page-link" th:href="@{/user/index/1}" th:unless="${pageResult.pageNum > 1}">上一页</a>
            </li>

            <li th:each="i : ${#numbers.sequence(1, pageResult.pages)}" class="page-item"
                th:classappend="${i == pageResult.pageNum} ? 'active' : ''">
                <a class="page-link" th:href="@{/user/index/{page}(page=${i})}" th:text="${i}"></a>
            </li>

            <li class="page-item" th:classappend="${pageResult.pageNum == pageResult.pages} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/user/index/{page}(page=${pageResult.pageNum + 1})}" th:if="${pageResult.pageNum < pageResult.pages}">下一页</a>
                <a class="page-link" th:href="@{/user/index/{page}(page=${pageResult.pages})}" th:unless="${pageResult.pageNum < pageResult.pages}">下一页</a>
            </li>
            <li class="page-item" th:classappend="${pageResult.pageNum == pageResult.pages} ? 'disabled' : ''">
                <a class="page-link" th:href="@{/user/index/{page}(page=${pageResult.pages})}">尾页</a>
            </li>
        </ul>
    </nav>

    <!-- 总数显示 -->
    <div class="text-center mt-3">
        共 <strong th:text="${pageResult.total}"></strong> 条帖子，当前第 <strong th:text="${pageResult.pageNum}"></strong> 页
    </div>

    <!-- 返回首页 -->
    <div class="mt-4 text-center">
        <a th:href="@{/user/index}" class="btn btn-secondary">返回首页</a>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>